package com.ruoyi.common.pay;

import com.alipay.api.internal.util.file.IOUtils;
import com.github.wxpay.sdk.WXPayConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

/**
 * @program: app微信支付资料
 * @description:
 * @author: Mr.Li
 * @create: 2019-10-26 13:41
 **/
@Component
public class MyWxPayConfig implements WXPayConfig {

    @Autowired
    private WxPayXiaoChengXuConfig wxPayXiaoChengXuConfig;

    /**
     * 加载证书 这里证书需要到微信商户平台进行下载
     */
    private byte[] certData;

    public MyWxPayConfig() throws Exception {
        InputStream certStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("apiclient_cert.p12");//证书需要到开放平台下载
        this.certData = IOUtils.toByteArray(certStream);
        certStream.close();
    }

    @Override
    public String getAppID() {
        return wxPayXiaoChengXuConfig.getAppid();
    }

    @Override
    public String getMchID() {
        return wxPayXiaoChengXuConfig.getMachid();
    }

    @Override
    public String getKey() {
        return wxPayXiaoChengXuConfig.getMckKey();
    }

    @Override
    public InputStream getCertStream() {
        return new ByteArrayInputStream(this.certData);
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 0;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 0;
    }

}